<?php
apf_require_class('Const_Img');
class Portal_Urls {

    public static function base_url() {
        $apf = APF::get_instance();
        $base_domain = $apf->get_config("base_domain");
        $url = 'http://' . $base_domain . '/';
        return $url;
    }



    /**
     * 根据controller返回URL
     * @param string $class_name
     * @param array $params
     */
    public static function build_url($class_name, $params = null) {
        $class_name = ereg_replace('Controller$', '', $class_name);
        $arr = explode("_", $class_name);
        $path = implode("/", $arr);
        $url = self::base_url(). $path . "/";
        if(null != $params) {
            $url .= APF_Util_StringUtils::encode_seo_parameters($params);
        }
        return $url;
    }

    public static function home_url($params = null){
        $url = self::base_url() . self::build_parameters($params);

        return $url;
    }

    public static function search_url($params = null){
        $url = self::base_url() . "search/" . self::build_parameters($params);

        return $url;
    }

    public static function logout_url(){
        $params = array("logout" => "1");
        $url = self::base_url() . self::build_parameters($params);

        return $url;
    }
    /**
     * 帮助中心
     * @return string
     */
    public static function help_url(){
        $url = self::base_url() . "help/" ;
        return $url;
    }
    /**
     * 个人资料编辑
     * @return string
     */
    public static function profile_url(){
        $url = self::base_url() . "profile/" ;
        return $url;
    }
    public static function ajax_upload_url(){
        $url = self::base_url() . "ajaxupload/" ;
        return $url;
    }
    /**
     * 用户头像
     * @param string $img_name  = user_code
     * @param int $size  7070=70*70
     * @return string
     */
    public static function build_user_pic_path($user_code,$img_name = "default.png"){
        $url = self::base_url() . "headpic/" ;
        $user_head_pic = $user_code.'/'.$img_name;
        if(!is_file(Const_Img::PATH_BASE.Const_Img::PATH_UPLOAD.$user_head_pic)) {
            $user_head_pic = 'default.png';
        }
        return $url.$user_head_pic;
    }

    /*
     * 人名/工号搜索
     * @return string
     */
    public static function ajax_search_user(){
        return self::base_url().'hr/ajax/SearchUser/';
    }
    /**
     * 职位搜索
     * @return string
     */
    public static function ajax_search_job(){
        return self::base_url().'hr/ajax/SearchJob/';
    }
    /**
     * 身份证
     * @return string
     */
    public static function ajax_id_card(){
        return self::base_url().'hr/ajax/GetIdCard/';
    }
    /**
     *
     */
    public static function ajax_recruit_search_job(){
        return self::base_url().'hr/ajax/SearchJobRecruit/';
    }

    /**
     * 用户安全验证
     * @return string
     */
    public static function ajax_check_user_security() {
        return self::base_url().'ajax/checksecurity/';
    }
    /**
     * 2013绽放
     * @return string
     */
    public static function ajax_2013_blossom() {
        return self::base_url().'ajax/Message/';
    }
    /**
     * 用户安全验证跳转
     * @return string
     */
    public static function jump_url() {
        return self::base_url().'jump/verify/';
    }
    //到招聘系统
    public static function lumesse_url(){
        return self::base_url().'lumesse/';
    }
    private function build_parameters($params = null){
        $q = "";
        if (empty($params)){
            return $q;
        }

        $_params = array();
        foreach($params as $key => $val){
            $_params[] = "{$key}={$val}";
        }
        $q = "?" . implode("&", $_params);
        return $q;
    }
    public static function build_active(){
        return self::base_url().'active/';
    }
}